package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.InterestTagsDAO;
import com.xinghou.platform.model.main.InterestTags;

/**
 * @author liuwei.wen
 *
 */
@Service
public class InterestTagsDAOImpl {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public InterestTags getInterestTagsById(Integer Id)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select Id,Tag_id,User_id from interest_tags where Id = ?";
		InterestTags interestTags = jdbcTemplate.queryForObject(sql, new Object[] { Id }, new InterestTagsMapper());
		CustomerContextHolder.clearCustomerType();
		return interestTags;
	}

	@Override
	public int updateInterestTags(InterestTags interestTags)throws DataAccessException {
		 StringBuffer strSQL = new StringBuffer("UPDATE interest_tags SET Tag_id=?,User_id=? where Id=?");	
         Object[] params = {interestTags.getTagId(), interestTags.getUserId(),interestTags.getId() };
         CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
         int ret = jdbcTemplate.update(strSQL.toString(),params);
         CustomerContextHolder.clearCustomerType();
         return ret;
	}

	@Override
	public int saveInterestTags(InterestTags interestTags)throws DataAccessException {
		StringBuffer strSQL = new StringBuffer("INSERT INTO interest_tags(Tag_id,User_id)values(?,?);");		
		Object[] params = {interestTags.getTagId(), interestTags.getUserId()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret=jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
	
	@Override
	public int delInterestTags(Integer userid) throws DataAccessException {
		String sql = "DELETE FROM interest_tags WHERE User_id=?";
		Object[] params = {userid};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(sql,params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public ArrayList<InterestTags> getInterestTagsByUserId(Integer userid)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Id,Tag_id,User_id FROM interest_tags where User_id = ?";
		ArrayList<InterestTags> list = (ArrayList<InterestTags>)jdbcTemplate.query(sql, new Object[] { userid }, new InterestTagsMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}

	private static final class InterestTagsMapper implements RowMapper<InterestTags> {
		public InterestTags mapRow(ResultSet rs, int rowNum) throws SQLException {
			InterestTags interestTags = new InterestTags();
			interestTags.setId(rs.getInt("Id"));
			interestTags.setTagId(rs.getInt("Tag_id"));
			interestTags.setUserId(rs.getInt("User_id"));
			return interestTags;
		}
	}*/

}
